<template>
  <div class="login-container">
    <div class="overlay"></div>
    <div class="login-box">
      <h1 class="login-title">音乐管理系统</h1>
      <div class="form-group">
        <select v-model="selectedRole" class="form-input">
          <option value="">请选择用户类型</option>
          <option value="admin">管理员</option>
          <option value="band">乐队用户</option>
          <option value="fan">乐迷</option>
        </select>
      </div>
      <div class="form-group">
        <input 
          type="text" 
          v-model="username" 
          placeholder="用户名"
          class="form-input"
        >
      </div>
      <div class="form-group">
        <input 
          type="password" 
          v-model="password" 
          placeholder="密码"
          class="form-input"
        >
      </div>
      <button @click="handleLogin" class="login-btn">
        登录
      </button>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { mockUsers } from '../mockData';

export default {
  name: 'Login',
  data() {
    return {
      username: '',
      password: '',
      selectedRole: '',
    };
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...mapActions(['login']),
    async handleLogin() {
      if (!this.selectedRole) {
        alert('请选择用户类型');
        return;
      }
      
      const user = mockUsers.find(u => 
        u.username === this.username && 
        u.password === this.password &&
        u.role === this.selectedRole
      );
      
      if (user) {
        await this.login(user);
        console.log('登录成功:', this.user);
        
        if (user.role === 'admin') {
          this.$router.push('/admin');
        } else if (user.role === 'band') {
          this.$router.push('/band');
        } else if (user.role === 'fan') {
          this.$router.push('/fan');
        }
      } else {
        alert('用户名或密码错误');
      }
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #16222A 0%, #3A6073 100%);
  position: relative;
  margin: 0;
  padding: 0;
}

.login-box {
  position: relative;
  width: 400px;
  padding: 40px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-title {
  color: #fff;
  text-align: center;
  margin-bottom: 35px;
  font-size: 30px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
}

.form-group {
  margin-bottom: 25px;
  width: 100%;
}

.form-input {
  width: 100%;
  padding: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  transition: all 0.3s ease;
}

select.form-input {
  appearance: none;
  cursor: pointer;
}

select.form-input option {
  background: #1a2830;
  color: #fff;
}

.form-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
}

.form-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(45deg, #2c5364, #203a43);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 1px;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #203a43, #2c5364);
}

@media (max-width: 480px) {
  .login-box {
    width: 90%;
    padding: 30px;
  }
}
</style>